<template>
    <div style="width:100%;height: 119px;">
        <img src="../../../assets/710@2x.webp" alt="" style="width: 100%;height: 100%;">
    </div>

    <div class="news-box">
        <p>
            <span style="color: #9a9a9a;font-size: 10px">最新消息</span>
            <span style="float: right;font-weight: 600;font-size: 10px">2025/03/13</span>
        </p>
        <p class="news-title">
            改写命运，集结你的 Waifu 军队，在 Zafira 中拯救世界
        </p>
        <p class="news-content">
            想象一下，在中世纪的奇幻世界中醒来，你不再只是普通的旅行者，而是注定要改写历史的英雄。你拥有传说中的龙之力量，身边围绕着身经百战的女英雄，肩负着拯救整个大陆免于毁灭的重任。听起来很史诗，对吧？好吧，这正是ZAFIRA带你进入的。
            这款 AFK 回合制 RPG 将策略、角色收集和浪漫融为一体，令人兴奋。无论您是组建完美的 5V5 战斗团队、升级女主角，还是建立深厚（和亲密）的联系，总有事情可做。...
        </p>
    </div>

    <!-- 最新消息 -->
    <div class="news-lastest">
        <p class="mb10 mt10" style="font-weight: 600;">最新消息</p>
        <div class="news-lastest-list">
            <template v-for="(item, index) in wzList" :key="index">
                <div class="news-lastest-item" @click="toDetails(item)">
                    <div class="news-lastest-item-img">
                        <img :src="item.cover" alt="" style="width: 100%;height: 100%;">
                    </div>
                    <div class="news-lastest-item-content">
                        <p style="font-size: 10px;line-height: 10px;">
                            <span style="color: #9a9a9a;">{{ item.title }}</span>
                        </p>
                        <p class="contentTxt">
                            {{ item.content }}
                        </p>
                        <p style="font-size: 10px;line-height: 10px;">
                            <span style="font-weight: 600;">{{ item.created_at }}</span>
                        </p>
                    </div>
                </div>

                <nut-divider style="color: #9a9a9a;"></nut-divider>
            </template>
        </div>
        <div class="game-btn">
            <div class="download-btn">
                更多文章
            </div>
        </div>
    </div>


    <!-- 官方公告 -->
    <div class="news-lastest">
        <p class="mb10 mt10" style="font-weight: 600;">官方公告</p>
        <div class="news-lastest-list">
            <template v-for="(item, index) in gfList" :key="index">
                <div class="news-lastest-item" @click="toDetails(item)">
                    <div class="news-lastest-item-img">
                        <img :src="item.cover" alt="" style="width: 100%;height: 100%;">
                    </div>
                    <div class="news-lastest-item-content">
                        <p style="font-size: 10px;line-height: 10px;">
                            <span style="color: #9a9a9a;">{{ item.title }}</span>
                        </p>
                        <p class="contentTxt">
                            {{ item.content }}
                        </p>
                        <p style="font-size: 10px;line-height: 10px;">
                            <span style="font-weight: 600;">{{ item.created_at }}</span>
                        </p>
                    </div>
                </div>
                <nut-divider style="color: #9a9a9a;"></nut-divider>
            </template>
        </div>
        <div class="game-btn">
            <div class="download-btn" style="background-color: #8492fd;">
                更多公告
            </div>
        </div>
    </div>

    <!-- 游戏更新 -->
    <div class="news-lastest">
        <p class="mb10 mt10" style="font-weight: 600;">游戏更新</p>
        <div class="news-lastest-list">
            <template v-for="(item, index) in yxList" :key="index">
                <div class="news-lastest-item" @click="toDetails(item)">
                    <div class="news-lastest-item-img img2">
                        <img :src="item.cover" alt="" style="width: 100%;height: 100%;">
                    </div>
                    <div class="news-lastest-item-content content2">
                        <p style="font-size: 10px;line-height: 10px;">
                            <span style="color: #9a9a9a;">{{ item.title }}</span>
                        </p>
                        <p class="contentTxt2">
                            {{ item.content }}
                        </p>
                        <p style="font-size: 10px;line-height: 16px;margin-bottom: 5px;color: #9a9a9a;">
                            {{ item.game_description }}
                        </p>
                        <p style="font-size: 10px;line-height: 10px;">
                            <span style="font-weight: 600;">HAREM HEROES‧{{ item.created_at }}</span>
                        </p>
                    </div>
                </div>
                <nut-divider style="color: #9a9a9a;"></nut-divider>
            </template>
        </div>
        <div class="game-btn">
            <div class="download-btn" style="background-color: #e222ff;">
                更多更新
            </div>
        </div>
    </div>
</template>

<script setup lang="ts">
import { axiosService } from '@http'
import { onBeforeMount, ref } from 'vue'
import { useRouter } from 'vue-router'

export interface ArticleListInterface {
    items: ArticleListItemInterface[]
    total_items: number
    limit: number
    first: number
    previous: number
    current: number
    next: number
    last: number
}

export interface ArticleListItemInterface {
    id: number
    title: string
    created_at: string
    cover: string
    content: string
    game_id: number
}

export interface YxListInterface {
    items: YxListItemInterface[]
    total_items: number
    limit: number
    first: number
    previous: number
    current: number
    next: number
    last: number
}

export interface YxListItemInterface {
    id: number
    title: string
    cover: string
    game_name: string
    game_description: string
    content: string
    type: number
    created_at: string
    status: number
}



const wzList = ref<ArticleListItemInterface[]>([])
const gfList = ref<ArticleListItemInterface[]>([])
const yxList = ref<YxListItemInterface[]>([])

const getList = async (typeId: number) => {
    const data = {
        category_id: typeId, // 1-最新消息 2-游戏更新 3-官方公告
        page: 1,
        size: 3
    }
    const res = await axiosService.post<ArticleListInterface>('/api/Article/articleList', data)
    if (res.code === 200 && res.data) return res.data.items
    return []
}

const getYxList = async (typeId: number) => {
    const data = {
        type: typeId, //1游戏更新 2限时活动
        page: 1, //分也
        game_id: 1,// 游戏id
        size: 3
    }
    const res = await axiosService.post<YxListInterface>('/api/Article/bulletinList', data)
    if (res.code === 200 && res.data) return res.data.items
    return []
}

onBeforeMount(async () => {
    wzList.value = await getList(1)
    gfList.value = await getList(3)
    yxList.value = await getYxList(1)
})

const router = useRouter()
const toDetails = (item) => {
    router.push({
        path: '/articleDetail',
        query: {
            id: item.id
        }
    })
}
</script>

<style scoped lang="scss">
.news-box {
    padding: 7px;

    .news-title {
        font-weight: 600;
        font-size: 15px;
        margin-top: 0;
        margin-bottom: 5px;
    }

    .news-content {
        font-size: 10px;
        line-height: 17px;
    }
}


.news-lastest {
    padding: 0 14px;
    margin-bottom: 20px;

    .news-lastest-item {
        display: flex;
        margin-bottom: 15px;

        .news-lastest-item-img {
            width: 147px;
            height: 73px;
            flex-grow: 0;

            &.img2 {
                width: 75px;
                height: 75px;
            }
        }

        .news-lastest-item-content {
            // flex-grow: 1;
            width: calc(100% - 147px);
            padding: 0 10px;

            &.content2 {
                width: calc(100% - 75px);
            }

            .contentTxt2 {
                font-size: 10px;
                font-weight: 600;
                line-height: 16px;
                margin-top: 2px;
                width: 100%;
                white-space: nowrap;
                overflow: hidden;
                text-overflow: ellipsis;
            }

            .contentTxt {
                font-size: 11px;
                font-weight: 600;
                line-height: 18px;
                margin-top: 9px;
                margin-bottom: 9px;
                width: 100%;
                white-space: normal;
                overflow: hidden;
                display: -webkit-box;
                text-overflow: ellipsis;
                -webkit-line-clamp: 2;
                /* 控制行数 */
                -webkit-box-orient: vertical;
            }
        }
    }
}


.game-btn {
    display: flex;
    justify-content: center;
    padding-top: 10px;

    .download-btn {
        width: 180px;
        background-color: #4960eb;
        color: #fff;
        border-radius: 20px;
        height: 33px;
        font-size: 13px;
        font-weight: bold;
        line-height: 33px;
        text-align: center;
    }
}
</style>
